package com.ai.util;

import java.util.ArrayList;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.ai.academiainteligente.*;

public class AcademiaAdapter extends BaseAdapter {

	ArrayList<Academia> academias;

	public AcademiaAdapter(ArrayList<Academia> academias) {
		this.academias = academias;
	}

	@Override
	public int getCount() {
		return academias.size();
	}

	@Override
	public Object getItem(int arg0) {
		return academias.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Academia academia = academias.get(position);
		ViewHolder holder;
		if (convertView == null) {
			convertView = LayoutInflater.from(parent.getContext()).inflate(
					R.layout.item_academia, null);
			holder = new ViewHolder();
			holder.fantasia = (TextView) convertView
					.findViewById(R.id.txtFantasia);
			holder.endereco = (TextView) convertView
					.findViewById(R.id.txtEndereco);
			holder.endereco2 = (TextView) convertView
					.findViewById(R.id.txtEndereco2);
			holder.fone = (TextView) convertView.findViewById(R.id.txtFone);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		holder.fantasia.setText(academia.getFantasia());
		holder.endereco.setText(academia.getEndereco() + ", "
				+ academia.getNumero());
		holder.endereco2.setText(academia.getBairro() + " - "
				+ academia.getCidade() + " - " + academia.getEstado());
		holder.fone.setText(academia.getTelefone());

		return convertView;
	}

	static class ViewHolder {
		TextView fantasia;
		TextView endereco;
		TextView endereco2;
		TextView fone;
	}

}
